<template>
  <el-select
    v-model="form.workshopCode"
    placeholder="请选择"
    style="width: 192px"
    clearable filterable
    @change="handleSearchListChange('workshopCode')"
  >
    <el-option
      v-for="(item, index) in workshopOptions"
      :key="index"
      :label="item.deptName"
      :value="item.deptId"
    >
    </el-option>
  </el-select>
</template>

<script setup>
import { getFactoryTree, depeIdSelectList } from "@/api/system/dept";

function handleSearchListChange(type) {
  if (type == "factory") {
    depeIdSelectList({
      deptType: "workShop",
      deptId: queryParams.value.factory,
    }).then((res) => {
      workshopOptions.value = res.data;
      lineOptions.value = [];
      processOptions.value = [];
      queryParams.value.workshopCode = "";
      queryParams.value.productLine = "";
      queryParams.value.sectionCode = "";
    });
  }
  if (type == "workshopCode") {
    depeIdSelectList({
      deptType: "line",
      deptId: queryParams.value.workshopCode,
    }).then((res) => {
      lineOptions.value = res.data;
      processOptions.value = [];
      queryParams.value.productLine = "";
      queryParams.value.sectionCode = "";
    });
  }
  if (type == "productLine") {
    depeIdSelectList({
      deptType: "section",
      deptId: queryParams.value.productLine,
    }).then((res) => {
      processOptions.value = res.data;
      queryParams.value.sectionCode = "";
    });
  }
}
</script>

<style lang="scss" scoped></style>
